package com.umeox.watch.moto.settings.ui;

import static com.umeox.moto.common.log.Logger.getTime;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;

import com.umeox.moto.common.utils.AndroidUtils;
import com.umeox.moto.watch.themes.app.ThemeAppCompatActivity;
import com.umeox.moto.watch.themes.widget.TextView;
import com.umeox.watch.moto.settings.R;
import com.umeox.watch.moto.settings.view.MarqueeTextView;

/**
 * Created by Rambo 2024/4/29/0029
 * Describe:
 */
public class DeviceInfoActivity extends ThemeAppCompatActivity {

    private static final long EXIT_TIMES = 2000;
    public static final String KEY_ANDROID_SETTINGS = "3363";
    private int count = 0;
    private long mLastTime;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_device_info);
        TextView tvIMEI = findViewById(R.id.tv_imei);
        tvIMEI.setText(AndroidUtils.getDeviceId());

        tvIMEI.setOnClickListener(v -> multipleClickEvent());

        MarqueeTextView tvFirmwareVersion = findViewById(R.id.tv_fv);
        tvFirmwareVersion.setText(Build.DISPLAY);

        TextView tvWifiMac = findViewById(R.id.tv_wif_mac);
        tvWifiMac.setText(AndroidUtils.getMacAddress1());
    }


    private void multipleClickEvent() {
        long currentTime = getTime(0);
        if ((currentTime - mLastTime) < EXIT_TIMES) {
            count++;
            if (count == 4) {
                mLastTime = currentTime;
                count = 0;
                showPasswordDialog();
            }
        } else {
            count = 1;
            mLastTime = currentTime;
        }
    }

    private void showPasswordDialog() {
        new AlertDialog.Builder(this)
                .setView(R.layout.dialog_settings).setNegativeButton("ok", (dialog, which) -> {
                    AlertDialog alertDialog = (AlertDialog) dialog;

                    EditText passwordEt = alertDialog.findViewById(R.id.et_password);

                    final String s = passwordEt.getText().toString();
                    if (TextUtils.equals(KEY_ANDROID_SETTINGS, s)) {
                        startSettingsActivity();
                    }
                }).setPositiveButton("cancel", (dialog, which) -> {

                }).create().show();
    }

    private void startSettingsActivity() {
        Intent chooseWifiIntent = new Intent();
        chooseWifiIntent.setClassName("com.android.settings", "com.android.settings.Settings");
        startActivity(chooseWifiIntent);
    }
}
